package com.schedule.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.schedule.common.result.Result;
import com.schedule.dto.LoginDto;
import com.schedule.service.AuthService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 认证控制器
 */
@RestController
@RequestMapping("/api/auth")
@RequiredArgsConstructor
public class AuthController {

    private final AuthService authService;

    /**
     * 用户登录
     */
    @PostMapping("/login")
    public Result<String> login(@RequestBody LoginDto loginDto) {
        String token = authService.login(loginDto);
        return Result.success("登录成功", token);
    }

    /**
     * 用户登出
     */
    @PostMapping("/logout")
    public Result<String> logout() {
        StpUtil.logout();
        return Result.success("登出成功");
    }

    /**
     * 获取用户信息
     */
    @GetMapping("/userinfo")
    public Result<Object> getUserInfo() {
        Object userInfo = authService.getUserInfo();
        return Result.success(userInfo);
    }
}